package com.yjymm.commonsdk.model;

import com.yjymm.commonsdk.common.exception.en.CommonResultEnum;
import lombok.Builder;
import lombok.Data;

/**
 * @author yjymm
 * @date 2020-12-26 0:08
 *
 * 统一返回对象
 */
@Builder(toBuilder = true)
@Data
public class CommonResult {

    /**
     * 返回的数据
     */
    private Object result;

    /**
     * 返回代码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回详细信息
     */
    private String detailMessage;

    /**
     * 成功与否
     */
    private Boolean success;


    public void setInfo (CommonResultEnum resultEnum) {
        this.setCode(resultEnum.getCode());
        this.setMessage(resultEnum.getMessage());
    }

    public CommonResult() {
    }

    public CommonResult(Object result, Integer code, String message) {
        this.result = result;
        this.code = code;
        this.message = message;
    }

    public CommonResult(Object result, CommonResultEnum resultEnum) {
        this.result = result;
        this.setCode(resultEnum.getCode());
        this.setMessage(resultEnum.getMessage());
    }

    public CommonResult(Object result, Integer code, String message, String detailMessage) {
        this.result = result;
        this.code = code;
        this.message = message;
        this.detailMessage = detailMessage;
    }


}
